<?php

/**
 * 店铺菜单管理
 * @version 1.0
 * @author ezhu <ezhu@jipukeji.com>
 */
namespace Shop\Event;

class MenuEvent{
    
    
    /**
     * 获取菜单列表  goto:yzs1013 左菜单设置
     */
    public function menuList($currUrl=''){
        $menu_list = array(
                'index' => array('name' => '首页', 'url'=>U('Store/index'), 'child' => array(
                        '常规设置' => array(
                                array('name' => '商品发布',    'url' =>U('Item/add'),'is_show'=>1),
                                array('name' => '商品列表',    'url' =>U('Item/index'),'is_show'=>1),
                                array('name' => '库存警报',    'url' =>U('Store/warning'),'is_show'=>1)
                        ),
                )),
                'item' => array('name' => '商品', 'url'=>U('Item/index'), 'op'=>'Item_index', 'child' => array(
                        '0' => array(
                                array('name' => '商品列表',    'url' =>U('Item/index'),'is_show'=>1),
                                array('name' => '商品发布',    'url' =>U('Item/add'), 'is_show'=>1),
                                // array('name' => '销售类目',    'url' =>U('ItemCategory/index'),'is_show'=>1),
                        		array('name' => '商品编辑',    'url' =>U('Item/edit'),'is_show'=>0),
                                // array('name' => '可销售区域',    'url' =>U('Item/available_zone'),'is_show'=>1),
                                array('name' => '独立指定区域',    'url' =>U('Item/position'),'is_show'=>1),
                        		array('name' => '商品评价',    'url' =>U('ItemComment/index'),'is_show'=>1),
                                array('name' => '商品属性',    'url' =>U('ItemProperty/index'),'is_show'=>0),
                        		array('name' => '设置属性值',    'url' =>U('ItemProperty/edit'),'is_show'=>0),
                                array('name' => '商品规格',    'url' =>U('ItemProperty/spec'),'is_show'=>0),
                                array('name' => '商品标签',    'url' =>U('ItemLabel/index'),'is_show'=>1),
                                array('name' => '库存警报',    'url' =>U('Store/warning'),'is_show'=>1),
                                array('name' => '添加商品标签',    'url' =>U('ItemLabel/add'),'is_show'=>0),
                                array('name' => '编辑商品标签',    'url' =>U('ItemLabel/edit'),'is_show'=>0),
                                array('name' => '商品分类整理',    'url' =>"javascript:spflzl()",'is_show'=>1)
                        )
                )),
                'order' => array('name' => '订单', 'url'=>U('Order/index'), 'op'=>'Order_index', 'child' => array(
                        '0'=>array(
                                array('name' => '订单管理',  'url'=>U('Order/index'),'is_show'=>1),
                                array('name' => '订单管理-订单详情',  'url'=>U('Order/view'),'is_show'=>0),
                                array('name' => '订单管理-订单发货',  'url'=>U('Ship/add'),'is_show'=>0),
                                array('name' => '订单管理-订单发货详情',  'url'=>U('Ship/view'),'is_show'=>0),
                                array('name' => '收款单',   'url'=>U('Payment/index'),'is_show'=>1),
                                array('name' => '发货单',   'url'=>U('Ship/index'),'is_show'=>1),
                                array('name' => '发货设置',  'url'=>U('Store/address'),'is_show'=>1),
                                array('name' => '发货设置',  'url'=>U('Store/editAdd'),'is_show'=>0),
                                array('name' => '订单修改',  'url'=>U('Order/update'),'is_show'=>0)
                        )
                )),
                'promotion' => array('name' => '促销', 'url'=>U('Coupon/index'), 'child' => array(
                        '0'=>array(
                                array('name' => '优惠券', 'url'=>U('Coupon/index'), 'is_show'=>1, 'rule_id'=>'1'),
                                    array('name'=>'编辑优惠券','url'=>U('Coupon/edit'),'is_show'=>0, 'rule_id'=>'1'),
                                    array('name'=>'添加优惠券','url'=>U('Coupon/add'),'is_show'=>0, 'rule_id'=>'1'),
                                    array('name'=>'优惠券用户','url'=>U('CouponUser/index'),'is_show'=>0, 'rule_id'=>'1'),
                                    array('name'=>'发放优惠券','url'=>U('CouponUser/add'),'is_show'=>0, 'rule_id'=>'1'),

                            array('name' => '满减', 'url'=>U('Manjian/index'), 'is_show'=>1, 'rule_id'=>'2'),
                            array('name' => '新增满减活动', 'url'=>U('Manjian/add'), 'is_show'=>0, 'rule_id'=>'2'),
                            array('name' => '编辑满减活动', 'url'=>U('Manjian/edit'), 'is_show'=>0, 'rule_id'=>'2'),
                            array('name' => '第二件折扣', 'url'=>U('SecondPieces/index'), 'is_show'=>1, 'rule_id'=>'3'),
                            array('name' => '新增第二件折扣', 'url'=>U('SecondPieces/add'), 'is_show'=>0, 'rule_id'=>'3'),
                            array('name' => '编辑第二件折扣', 'url'=>U('SecondPieces/edit'), 'is_show'=>0, 'rule_id'=>'3'),
                            array('name' => '买送', 'url'=>U('BuySend/index'), 'is_show'=>1, 'rule_id'=>'4'),
                            array('name' => '新增买送商品规则', 'url'=>U('BuySend/add'), 'is_show'=>0, 'rule_id'=>'4'),
                            array('name' => '编辑买送商品规则', 'url'=>U('BuySend/edit'), 'is_show'=>0, 'rule_id'=>'4'),
                            array('name' => '老客户立减', 'url'=>U('Fugou/index'), 'is_show'=>1, 'rule_id'=>'5'),
                            array('name' => '新增立减优惠商品', 'url'=>U('Fugou/add'), 'is_show'=>0, 'rule_id'=>'5'),
                            array('name' => '编辑立减优惠商品', 'url'=>U('Fugou/edit'), 'is_show'=>0, 'rule_id'=>'5'),
                            array('name' => '拼团活动', 'url'=>U('Join/index'), 'is_show'=>1,'rule_id'=>'0'),
                            array('name' => '拼团商品列表', 'url'=>U('Join/joinItem'), 'is_show'=>0,'rule_id'=>'0'),
                            array('name' => '编辑拼团商品', 'url'=>U('Join/editItem'), 'is_show'=>0,'rule_id'=>'0'),
                            array('name' => '拼团订单列表', 'url'=>U('Join/orderList'), 'is_show'=>0,'rule_id'=>'0'),
                            array('name' => '拼团订单详情', 'url'=>U('Join/joinView'), 'is_show'=>0,'rule_id'=>'0'),
                            array('name' => '秒杀活动', 'url'=>U('Seckill/activity'), 'is_show'=>1, 'rule_id'=>'0'),
                            array('name' => '新增秒杀活动', 'url'=>U('Seckill/add'), 'is_show'=>0, 'rule_id'=>'0'),
                            array('name' => '编辑秒杀活动', 'url'=>U('Seckill/edit'), 'is_show'=>0, 'rule_id'=>'0'),
                            array('name' => '秒杀商品管理', 'url'=>U('Seckill/itemList'), 'is_show'=>0, 'rule_id'=>'0'),
                            array('name' => '秒杀活动', 'url'=>U('Seckill/index'), 'is_show'=>0, 'rule_id'=>'0'),
                            array('name' => '编辑秒杀商品', 'url'=>U('Seckill/editItem'), 'is_show'=>0, 'rule_id'=>'0'),

                        )
                )),
                'store' => array('name' => '店铺', 'url'=>U('Store/set'), 'child' => array(
                        '0' => array(
                                array('name' => '店铺设置', 'url'=>U('Store/set'), 'is_show'=>1),
                                array('name' => '店铺导航', 'url'=>U('Store/nav'), 'is_show'=>1),
                                array('name' => '编辑导航', 'url'=>U('Store/editNav'), 'is_show'=>0),
                                array('name' => '店铺信息', 'url'=>U('Store/info'), 'is_show'=>1),
                                array('name' => '店铺地址修改申请', 'url'=>U('Store/editAddress'), 'is_show'=>0),
                                array('name' => '店铺分类', 'url'=>U('Store/storeClass'), 'is_show'=>1),
                                array('name' => '编辑店铺分类', 'url'=>U('Store/editClass'), 'is_show'=>0),
                                array('name' => '品牌申请', 'url'=>U('Store/brand'), 'is_show'=>1),
                                array('name' => '品牌申请', 'url'=>U('Store/brandEdit'), 'is_show'=>0),
                                array('name' => '网页幻灯片', 'url'=>U('Store/slide'), 'is_show'=>1),
                                array('name' => '网页手机幻灯片', 'url'=>U('Store/slides'), 'is_show'=>1),
                                array('name' => '站内消息', 'url'=>U('Store/message'), 'is_show'=>1),
                                array('name' => '站内消息', 'url'=>U('Store/detailMsg'), 'is_show'=>0),
                                array('name' => '编辑幻灯片', 'url'=>U('Store/editSlide'), 'is_show'=>0),
                                array('name' => '新增幻灯片', 'url'=>U('Store/addSlide'), 'is_show'=>0),
                                array('name' => '商户修改后台登陆密码', 'url'=>U('Store/updatePassword'), 'is_show'=>0),
                        )
                        
                )),
                'transport' => array('name' => '物流', 'url'=>U('Transport/index'), 'child' => array(
                        '0' => array(
                                array('name' => '运费模板', 'url'=>U('Transport/index'), 'is_show'=>'1'),
                                array('name' => '编辑运费模板', 'url'=>U('Transport/edit'), 'is_show'=>'0'),
                                array('name' => '免运费额度', 'url'=>U('Transport/free_freight'), 'is_show'=>'1'),
                        )
                )),
                /*'consult' => array('name' => '客服', 'url'=>"javascript:alert('敬请期待');", 'child' => array(
                        '0' => array(
                                array('name' => '客服设置', 'url'=>'store_callcenter', 'op'=>'index'),
                                array('name' => '咨询管理', 'url'=>'store_consult', 'op'=>'consult_list'),
                                array('name' => '投诉管理', 'url'=>'store_complain', 'op'=>'list'),
                        )
        
                )),*/
                'service' => array('name' => '售后', 'url'=>U('Service/refund'), 'child' => array(
                        '0' => array(
                                array('name' => '退款记录', 'url'=>U('Service/refund'), 'is_show'=>'1'),
                        )
        
                )),
                'settle' => array('name' => '结算', 'url'=>U('Bill/index'), 'child' => array(
                        '0' => array(
                                array('name' => '结算管理', 'url'=>U('Bill/index'), 'is_show'=>'1'),
                                array('name' => '申请提现', 'url'=>U('Bill/add'), 'is_show'=>'1'),
                                array('name' => '提现列表', 'url'=>U('Bill/cashList'), 'is_show'=>'1'),
                        )
        
                )),
                'statistics' => array('name' => '统计', 'url'=>U('Stat/index'), 'child' => array(
                        '0' => array(
                                array('name' => '订单统计', 'url'=>U('Stat/index'), 'is_show'=>'1'),
                                array('name' => '销量统计', 'url'=>U('Stat/goods'), 'is_show'=>'1'),
                        )
                ))
                /* 'account' => array('name' => '帐号', 'url'=>"javascript:alert('敬请期待');", 'child' => array(
                        '0' => array(
                                array('name' => '操作日志', 'url'=>'seller_log', 'op'=>'log_list'),
                        )
        
                )) */
        );
        // 区域价格
        if(C('START_POSITION') != 1 ){
            unset($menu_list['item']['child'][0][3]);
        }

        $parsedUrl = parse_url($_SERVER["REQUEST_URI"]);
        $path = isset($parsedUrl['path'])? $parsedUrl['path'] : '';
        $directory = dirname($path);
        $directory=preg_replace("/\/Shop\/.*/i","",$directory);//----yzs1013 处理左边的栏目 subNav
        $currUrl = $currUrl ? : strtolower($directory.'/shop/'.CONTROLLER_NAME.'/'.ACTION_NAME.'.html');
        $menu_list['subNav'] = array();
        if($currUrl == strtolower($menu_list['index']['url'])){
            $menu_list['index']['class'] = 'current';
            $menu_list['subNav'] = $menu_list['index']['child'];
        }else{
            foreach ($menu_list as $key=>$val){
                if(!empty($val['child']) && $key != 'index'){
                    foreach ($val['child'] as $k=>$v){
                        if(!empty($v)){
                            foreach ($v as $ks=>$vs){
                                if($currUrl  == strtolower($vs['url'])){
                                    $menu_list[$key]['class'] = 'current';
                                    $menu_list['subNav'][] = $v;
                                }
                            }
                        }
                    }
                }
            }
        }
        //根据登陆用户商店等级不一样，显示不同的促销类型
        $marketing = $_SESSION['jipushop_store']['seller_user']['marketing'];
        $_list = str2arr($marketing);
        if (!empty($marketing)) {
            if (isset($menu_list['promotion']['class'])) {
                foreach ($menu_list['promotion']['child'][0] as $key => $value) {
                    if (!in_array($value['rule_id'],$_list) && ($value['rule_id'] > 0)) {
                        unset($menu_list['promotion']['child'][0][$key]);
                        unset($menu_list['subNav'][0][$key]);
                    }
                }
            }else{
                foreach ($menu_list['promotion']['child'][0] as $key => $value) {
                    if (!in_array($value['rule_id'],$_list)) {
                        unset($menu_list['promotion']['child'][0][$key]);
                    }
                }
                $promotion = array_values($menu_list['promotion']['child'][0]);
                $menu_list['promotion']['url'] = $promotion[0]['url'];
            }
            
        }else{
            unset($menu_list['promotion']['child'][0][0]);
            unset($menu_list['promotion']['child'][0][1]);
            unset($menu_list['promotion']['child'][0][2]);
            unset($menu_list['promotion']['child'][0][3]);
            unset($menu_list['promotion']['child'][0][4]);
            unset($menu_list['promotion']['child'][0][5]);
            unset($menu_list['promotion']['child'][0][6]);
            unset($menu_list['promotion']['child'][0][7]);
            unset($menu_list['promotion']['child'][0][8]);
            unset($menu_list['promotion']['child'][0][9]);
            unset($menu_list['promotion']['child'][0][10]);
            unset($menu_list['promotion']['child'][0][11]);
            unset($menu_list['promotion']['child'][0][12]);
            unset($menu_list['promotion']['child'][0][13]);
            unset($menu_list['promotion']['child'][0][14]);
            unset($menu_list['promotion']['child'][0][15]);
            unset($menu_list['promotion']['child'][0][16]);
            $menu_list['promotion']['url'] = '/Shop/Join/index.html';
            unset($menu_list['subNav'][0][0]);unset($menu_list['subNav'][0][1]);unset($menu_list['subNav'][0][2]);
            unset($menu_list['subNav'][0][3]);unset($menu_list['subNav'][0][4]);unset($menu_list['subNav'][0][5]);
            unset($menu_list['subNav'][0][6]);unset($menu_list['subNav'][0][7]);unset($menu_list['subNav'][0][8]);
            unset($menu_list['subNav'][0][9]);unset($menu_list['subNav'][0][10]);unset($menu_list['subNav'][0][11]);
            unset($menu_list['subNav'][0][12]);unset($menu_list['subNav'][0][13]);unset($menu_list['subNav'][0][14]);
            unset($menu_list['subNav'][0][15]);unset($menu_list['subNav'][0][16]);
        }
        return $menu_list;
    }
}